<?php
	include_once "xAP-functions/webincludes.php";
// build search list
$id=intval($_GET["id"]);
$startdate=intval($_GET["st"]);
$enddate=intval($_GET["en"]);

if ($id>0){
	
	$sql="select Location from xAP_Pictures_Source where SourceID=".$id;
	$results=dbquery($sql);
	if($startdate==0){
		$startdate=strtotime(" - 2 hours");
		$enddate=time();
	}
	$title=date("H:i",$startdate)." to ".date("H:i",$enddate);
	$sql="SELECT CreatedDateStamp,ItemID FROM xap_pictures_item 
	where SourceID=".$id." 
	and createddatestamp between '".date("Y-m-d H:i:s",$startdate)."' and '".date("Y-m-d H:i:s",$enddate)."'
	order by ItemID ";
	//SELECT * FROM xap_pictures_item where createddatestamp between '2008-12-25 00:00:00' and '2008-12-25 23:59:59'
	
	//echo $sql;
	$results=dbquery($sql);
	//echo $sql;

	foreach($results as $v){
		$dt=substr(date("i",strtotime($v["CreatedDateStamp"])),0,1);
		$item[date("H:",strtotime($v["CreatedDateStamp"])).$dt."0"][]="<img src='/Pictures/image.php?id=".$v["ItemID"]."&type=1' title='".$v["CreatedDateStamp"]."' width=160 height=120>";
	}
}

$q="?";
header("Content-type: text/xml");
?>
<<?=$q?>xml version="1.0" encoding="UTF-8"?>
<root>
<title set="waPicturesImage"><?=$title?></title>
<part>
<destination mode="replace" zone="waPicturesImage"  create="true"/>
<data><![CDATA[
<? foreach($item as $k=>$v):?>
<div class="iBlock">
<h3><?=$k?></h3>
<p>
<?foreach($v as $i):?>
<?=$i?>
<?endforeach?>
</p>
</div>
<? endforeach;?>
]]></data>
</part>
</root>